package com.example.chatserver;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class ChatServer {
	public static void main(String[] args) {
		new ChatServer().start(50000);
	}

	public void start(int port) {
		ServerSocket server; // 서버소켓.
		Socket socket; // 소켓.
		ChatServerThread thread;

		try {
			server = new ServerSocket(port);
			System.err.println("채팅서버 시작 :" + port);
			while (true) {
				try {
					// wait for connecting
					socket = server.accept();
					InetAddress address = socket.getInetAddress();
					System.out.println(address);
					System.err.println("socket accepted! ");

					// chatting server thread start
					thread = new ChatServerThread(socket);
					thread.start();
				} catch (IOException e) {
				}
			}
		} catch (IOException e) {
			System.err.println(e);
		}
	}
}
